<?php

namespace Acme\TestBundle\Controller;

use Acme\TestBundle\Entity\Teacher;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
 * Class TeacherController
 * @package Acme\TestBundle\Controller
 * @Route("/teacher")
 */
class TeacherController extends Controller
{
    /**
     * @Route("/create")
     */
    public function createAction(){
        $teacher = new Teacher();
        $teacher->setName('赵三');

        $em = $this->getDoctrine()->getManager();

        $em->persist($teacher);

        $em->flush();

        var_dump($teacher->getId());die();
    }

    /**
     * @Route("/get")
     */
    public function getAction(){
        $repository = $this->getDoctrine()->getRepository('AcmeTestBundle:Teacher');

        $teacher = $repository->find(1);

        $teacher = $repository->findOneBy(array('id'=>2));

        $teacher = $repository->findByName('王五');

        $teacher = $repository->findAll();

        echo '<pre>';
        var_dump($teacher);
        echo '</pre>';
        die();
    }
}
